package com.ssy.lingxi.open.api.controller.afterSale;

import cn.hutool.json.JSONUtil;
import com.ssy.lingxi.after.sale.api.model.constant.OpenApiMethodTypeEnum;
import com.ssy.lingxi.after.sale.api.model.vo.request.OpenApiCommonVO;
import com.ssy.lingxi.after.sale.api.model.vo.request.api.ApiReturnSubmitVerifyVO;
import com.ssy.lingxi.after.sale.api.model.vo.request.api.ApiVerifyVO;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.component.rabbitMQ.constants.MessageConstants;
import com.ssy.lingxi.component.rabbitMQ.service.IRabbitMQUtils;
import com.ssy.lingxi.open.api.controller.ApiBaseController;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 *  售后-退货类
 * @author ds
 * @date 2021/10/14
 * @version 2.0.0
 */
@RestController
@RequestMapping("/openApi/as/returnGoods")
public class ReturnController extends ApiBaseController {

    @Resource
    private IRabbitMQUtils rabbitMQUtils;

/*    private OpenApiCommonVO buildApiVO(Long memberId, Long roleId, JSONObject data){
        OpenApiCommonVO vo=new OpenApiCommonVO();
        vo.setMemberId(memberId);
        vo.setRoleId(roleId);
        vo.setData(data);
        return vo;
    }*/

    /**
     * 提交审核
     * @param submitVerifyVO
     * @return 是否成功
     */
    @RequestMapping(value = "/submitVerify", method = RequestMethod.POST)
    public Wrapper<Boolean> submitVerify(@RequestBody @Valid ApiReturnSubmitVerifyVO submitVerifyVO){
        //校验用户是否登录
        this.checkLogin();
        //存入消息队列中
        OpenApiCommonVO vo=new OpenApiCommonVO();
        vo.setApiType(OpenApiMethodTypeEnum.return_submit_verify.getCode());
        vo.setMemberId(submitVerifyVO.getMemberId());
        vo.setRoleId(submitVerifyVO.getRoleId());
        vo.setData(JSONUtil.parseObj(submitVerifyVO));
        rabbitMQUtils.sendMsg(MessageConstants.OPEN_API_AS_RETURN_EXCHANGE, MessageConstants.OPEN_API_AS_RETURN_ROUTINGKEY, JSONUtil.toJsonStr(vo));
        return Wrapper.success(true);
    }

    /**
     * 审核退货申请单一级
     * @param apiVerifyVO
     * @return
     */
    @RequestMapping(value = "/verifyStepOne", method = RequestMethod.POST)
    public Wrapper<Boolean> verifyStepOne(@RequestBody @Valid ApiVerifyVO apiVerifyVO){
        //校验用户是否登录
        this.checkLogin();
        //存入消息队列中
        OpenApiCommonVO vo=new OpenApiCommonVO();
        vo.setApiType(OpenApiMethodTypeEnum.return_verify_step_one.getCode());
        vo.setMemberId(apiVerifyVO.getMemberId());
        vo.setRoleId(apiVerifyVO.getRoleId());
        vo.setData(JSONUtil.parseObj(apiVerifyVO));
        rabbitMQUtils.sendMsg(MessageConstants.OPEN_API_AS_RETURN_EXCHANGE, MessageConstants.OPEN_API_AS_RETURN_ROUTINGKEY, JSONUtil.toJsonStr(vo));
        return Wrapper.success(true);
    }

    /**
     * 审核退货申请单二级
     * @param apiVerifyVO
     * @return
     */
    @RequestMapping(value = "/verifyStepTwo", method = RequestMethod.POST)
    public Wrapper<Boolean> verifyStepTwo(@RequestBody @Valid ApiVerifyVO apiVerifyVO){
        //校验用户是否登录
        this.checkLogin();
        //存入消息队列中
        OpenApiCommonVO vo=new OpenApiCommonVO();
        vo.setApiType(OpenApiMethodTypeEnum.return_verify_step_two.getCode());
        vo.setMemberId(apiVerifyVO.getMemberId());
        vo.setRoleId(apiVerifyVO.getRoleId());
        vo.setData(JSONUtil.parseObj(apiVerifyVO));
        rabbitMQUtils.sendMsg(MessageConstants.OPEN_API_AS_RETURN_EXCHANGE, MessageConstants.OPEN_API_AS_RETURN_ROUTINGKEY, JSONUtil.toJsonStr(vo));
        return Wrapper.success(true);
    }

    /**
     * 确认退货申请单
     * @param apiVerifyVO
     * @return
     */
    @RequestMapping(value = "/confirmVerify", method = RequestMethod.POST)
    public Wrapper<Boolean> confirmVerify(@RequestBody @Valid ApiVerifyVO apiVerifyVO){
        //校验用户是否登录
        this.checkLogin();
        //存入消息队列中
        OpenApiCommonVO vo=new OpenApiCommonVO();
        vo.setApiType(OpenApiMethodTypeEnum.return_confirm_verify.getCode());
        vo.setMemberId(apiVerifyVO.getMemberId());
        vo.setRoleId(apiVerifyVO.getRoleId());
        vo.setData(JSONUtil.parseObj(apiVerifyVO));
        rabbitMQUtils.sendMsg(MessageConstants.OPEN_API_AS_RETURN_EXCHANGE, MessageConstants.OPEN_API_AS_RETURN_ROUTINGKEY, JSONUtil.toJsonStr(vo));
        return Wrapper.success(true);
    }

}
